package com.rd.student.jiaji.class3.wangyanbo.task27;

import java.io.*;

public class TestBuffered {
    public static void main(String[] args) throws Exception{
//        File file = new File("stream.txt");
//        FileInputStream fis = new FileInputStream("stream.txt");
//        InputStream is = new BufferedInputStream(fis);
//        byte[] arr=new byte[(int)file.length()];
//        is.read(arr);
//        System.out.println(new String(arr));
//        is.close();
//        fis.close();
        copyFile("stream.txt","streamBuffered.txt");
    }
    public static void copyFile(String srcPath,String destPath)
            throws Exception{
        //建立输入流和输出流
        InputStream is = new BufferedInputStream(
                new FileInputStream(srcPath));
        OutputStream os = new BufferedOutputStream(
                new FileOutputStream(destPath));
        byte[] arr=new byte[1024];
        int len = 0;
        //(len = is.read(arr))>0也是一样的逻辑
        while((len = is.read(arr))!=-1){
            os.write(arr,0,len);
        }
        //是一次强制刷新操作
//        os.flush();
        os.close();
        is.close();
    }
}
